//
//  SceneDeviceCell.m
//  wAudioShare
//
//  Created by Anson on 14-11-7.
//  Copyright (c) 2014年 赵帅. All rights reserved.
//

#import "SceneDeviceCell.h"

#import "SceneDeviceModel.h"
#import "ArmModel.h"

@interface SceneDeviceCell ()

@property (weak, nonatomic) IBOutlet UILabel *sceneTitleLabel;

//@property (weak, nonatomic) IBOutlet

@end


@implementation SceneDeviceCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)setSceneData:(id)sceneData {
    
    if (!sceneData) {
        return;
    }
    
    self.switchBtn.hidden = YES;
    self.modeBtn.hidden = YES;
    self.temperatureBtn.hidden = YES;
    
    if ([sceneData isMemberOfClass:SceneDeviceModel.class]) {
        
        SceneDeviceModel *deviceData = (SceneDeviceModel *)sceneData;

    
    self.sceneTitleLabel.text = deviceData.title;
    
    switch (deviceData.deviceType) {
        case SceneDeviceTypeBinarySensor:
        case SceneDeviceTypeSwitch:
        case SceneDeviceTypeMotor:
        case SceneDeviceTypePowerMeter:
        case SceneDeviceTypeDoorLock:
        {
            self.switchBtn.hidden = NO;
            [self.switchBtn setTitle:(deviceData.isOn ? @"ON":@"OFF") forState:UIControlStateNormal];
            break;
        }
            
        case SceneDeviceTypeDimmer:
        {
            self.switchBtn.hidden = NO;
            [self.switchBtn setTitle:[NSString stringWithFormat:@"%ld%%", deviceData.percent] forState:UIControlStateNormal];
            break;
        }
            
        case SceneDeviceTypeThermostat:{
            self.switchBtn.hidden = NO;
            if (deviceData.isOn) {

                [self.switchBtn setTitle:@"ON" forState:UIControlStateNormal];
                self.modeBtn.hidden = NO;
                [self.modeBtn setTitle:deviceData.mode forState:UIControlStateNormal];
                
                if ([deviceData.mode.lowercaseString isEqualToString:@"heat"]
                    || [deviceData.mode.lowercaseString isEqualToString:@"cool"]) {
                    
                    self.temperatureBtn.hidden = NO;
                    [self.temperatureBtn setTitle:[NSString stringWithFormat:@"%ld℃",deviceData.thermostatTemperature] forState:UIControlStateNormal];
                }
                
            }else {

                [self.switchBtn setTitle:@"OFF" forState:UIControlStateNormal];
            }
            
            break;
        }
        
        case SceneDeviceTypeMultilevelSensor:
        case SceneDeviceTypeThermostatTemperature:{
           
            self.temperatureBtn.hidden = NO;
            [self.temperatureBtn setTitle:[NSString stringWithFormat:@"%ld℃", deviceData.thermostatTemperature] forState:UIControlStateNormal];
            
            break;
        }
            
        default:
            break;
    }
        
        
    }else if ([sceneData isMemberOfClass:ArmModel.class]) {
        
        ArmModel *armModel = (ArmModel *)sceneData;
        self.sceneTitleLabel.text = armModel.label;
        self.switchBtn.hidden = NO;
        [self.switchBtn setTitle:(armModel.active ? @"ON":@"OFF") forState:UIControlStateNormal];
        
    }
    
    
}

@end
